import eslint from '@eslint/js';
import eslintPrettier from 'eslint-plugin-prettier';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import importSort from 'eslint-plugin-simple-import-sort';
import globals from 'globals';
import tseslint from 'typescript-eslint';

const frontMonitorConfig = {
  files: ['**/*.{ts,tsx}'],
  languageOptions: {
    globals: globals.browser,
    ecmaVersion: 2022
  },
  plugins: {
    'react-hooks': reactHooks,
    'react-refresh': reactRefresh
  },
  rules: {
    '@typescript-eslint/no-unused-vars': [
      'error',
      {
        argsIgnorePattern: '^_', // 允许未使用参数以 _ 开头
        varsIgnorePattern: '^_', // 允许未使用变量以 _ 开头
        caughtErrorsIgnorePattern: '^_'
        // 关闭对枚举成员的误判
        // ignoreEnums: true
      }
    ],
    'no-var': 'error', // 不能有var声明变量
    '@typescript-eslint/ban-ts-ignore': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
    '@typescript-eslint/no-var-requires': 'off',
    '@typescript-eslint/no-empty-function': 'off',
    'vue/custom-event-name-casing': 'off',
    'no-use-before-define': 'off',
    '@typescript-eslint/no-use-before-define': 'off',
    '@typescript-eslint/ban-ts-comment': 'off',
    // '@typescript-eslint/ban-types': 'error',
    '@typescript-eslint/no-non-null-assertion': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    // 强制使用分号
    // '@typescript-eslint/semi': ['error', 'always'],
    'no-unused-vars': [
      'error',
      {
        argsIgnorePattern: '^_',
        varsIgnorePattern: '^_',
        caughtErrorsIgnorePattern: '^_',
        args: 'none'
      }
    ],
    'space-before-function-paren': 'off',
    // 'linebreak-style': ['error', 'unix'], // 使用 Unix 风格的换行符
    quotes: ['error', 'single'], // 使用单引号
    semi: ['error', 'always'], // 语句末尾不加分号
    'no-debugger': 'off', // 生产环境中警告 debugger 使用，开发环境中关闭规则
    'prefer-const': [
      // 常量用const
      'warn',
      { destructuring: 'all', ignoreReadBeforeAssign: true }
    ],
    'no-empty': ['error', { allowEmptyCatch: true }],
    'no-void': 'error'
  }
};

const baseConfig = {
  ignores: ['dist'],
  extends: [eslint.configs.recommended, ...tseslint.configs.recommended],
  plugins: { prettier: eslintPrettier, 'simple-import-sort': importSort },
  rules: {
    'simple-import-sort/imports': 'error'
    // "prettier/prettier": "error",
  }
};

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.recommended,
  baseConfig,
  frontMonitorConfig
);
